package com.lindroy.androidplayer.ui.main.fragment

import android.os.Bundle
import androidx.fragment.app.viewModels
import com.lindroy.androidplayer.R
import com.lindroy.androidplayer.base.BaseLazyFragment
import com.lindroy.androidplayer.databinding.FragmentFindBinding
import com.lindroy.androidplayer.ui.adapter.FindTabAdapter
import com.lindroy.androidplayer.utils.contactToViewPager
import com.lindroy.androidplayer.viewmodels.FindViewModel

/**
 * @author Lin
 * @date 2022/1/10
 * @function 首页-发现
 * @Description
 */
class FindFragment : BaseLazyFragment<FragmentFindBinding>() {

    private val viewModel by viewModels<FindViewModel>()

    private val tabIds = arrayListOf(
        R.string.square,
        R.string.knowledge_system,
        R.string.navigation_index,
        R.string.q_and_a
    )

    override fun FragmentFindBinding.initView(savedInstanceState: Bundle?) {
        vm = viewModel
        vpFind.offscreenPageLimit = tabIds.size
        vpFind.adapter = FindTabAdapter(this@FindFragment).apply { setData(tabIds) }
        tab.tabLayout.contactToViewPager(vpFind, tabIds.map { getString(it) })
    }

    override fun FragmentFindBinding.initListener() {
        viewModel.searchClickListener.observe(viewLifecycleOwner){
            activityNavController.navigate(R.id.action_to_search)
        }
    }

    override fun lazyLoad() {}

    companion object {
        fun newInstance() = FindFragment()
    }

}